package com.mxpio.erp.mes.controller;

import com.mxpio.erp.common.mes.entity.*;
import com.mxpio.erp.common.mes.service.*;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Order;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : wpp
 * @Datetime : 2023/9/1 11:30
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
@Tag(name = "AoiViewController", description = "aoi相关视图接口")
@RestController
@RequestMapping("/erp/mes/aoi/")
public class AoiViewController {
    @Autowired
    private VAoiLineSumByDayService vAoiLineSumByDayService;
    @Autowired
    private VAoiDaySumService vAoiDaySumService;
    @Autowired
    private VAoiDayTwoHoursSumService vAoiDayTwoHoursSumService;
    @Autowired
    private VAoiModelDaySumService vAoiModelDaySumService;
    @Autowired
    private VAoiModelNgDaySumService vAoiModelNgDaySumService;
    @Autowired
    private VAoiDayPpmService vAoiDayPpmService;
    @Autowired
    private VAoiLineDayDefectSumService aoiLineDayDefectSumService;

    @GetMapping("linesumbyday/list")
    @Operation(summary = "aoi检测按天汇总（产量+合格率）", description = "aoi检测按天汇总（产量+合格率）", method = "GET")
    public Result<VAoiLineSumByDay> spiLineSumByDayList(Criteria criteria)  {
        List<VAoiLineSumByDay> list = vAoiLineSumByDayService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }

    @GetMapping("aoidaysum/list")
    @Operation(summary = "aoi按天检测量（按小板汇总）", description = "aoi按天检测量（按小板汇总）", method = "GET")
    public Result<VAoiDaySum> aoiDaySumList(Criteria criteria)  {
        List<VAoiDaySum> list = vAoiDaySumService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }
    @GetMapping("aoimodeldaysum/list")
    @Operation(summary = "aoi设备按天检测量（按小板汇总）", description = "aoi设备按天检测量（按小板汇总）", method = "GET")
    public Result<List<VAoiModelDaySum>> aoiModelDaySumList(Criteria criteria)  {
        List<VAoiModelDaySum> list = vAoiModelDaySumService.list(criteria);
        return Result.OK(list);
    }
    @GetMapping("aoimodelngdaysum/list")
    @Operation(summary = "aoi设备按天NG检测量（按小板汇总）", description = "aoi设备按天NG检测量（按小板汇总）", method = "GET")
    public Result<List<VAoiModelNgDaySum>> aoiModelNgDaySumList(Criteria criteria)  {
        Pageable page = PageRequest.of(0, 10);//取10条
        if (criteria==null){
            criteria = Criteria.create();
        }
        criteria.addOrder(new Order("ngSum",true));
        Page<VAoiModelNgDaySum> vAoiModelNgDaySums = vAoiModelNgDaySumService.listPage(page, criteria);
        return Result.OK(vAoiModelNgDaySums.getContent());
    }
    @GetMapping("aoidaytwohourssum/list")
    @Operation(summary = "aoi按天两小时合计检测量（按小板汇总）", description = "aoi按天两小时合计检测量（按小板汇总）", method = "GET")
    public Result<List<VAoiDayTwoHoursSum>> aoiDayTwoHoursSumList(Criteria criteria)  {
        List<VAoiDayTwoHoursSum> list = vAoiDayTwoHoursSumService.list(criteria);
        return Result.OK(list);
    }

    @GetMapping("dayppm/list")
    @Operation(summary = "aoi按天ppm趋势", description = "aoi按天ppm趋势", method = "GET")
    public Result<VAoiDayPpm> aoippmList(Criteria criteria)  {
        List<VAoiDayPpm> list = vAoiDayPpmService.list(criteria);
        if (list.size()>0){
            return Result.OK(list.get(0));
        }
        return Result.OK();
    }
    @GetMapping("daydefectsum/list")
    @Operation(summary = "aoi明细按天 分组汇总DEFECT数量", description = "aoi明细按天 分组汇总DEFECT数量", method = "GET")
    public Result<List<VAoiLineDayDefectSum>> aoiLineDayDefectSumList(Criteria criteria)  {
        List<VAoiLineDayDefectSum> list = aoiLineDayDefectSumService.list(criteria);
        return Result.OK(list);
    }

}
